package demo.springcloud.getwary.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;



@RestController
@Slf4j
public class HomeController {
    @GetMapping("/")
    public ResponseEntity<String> index(ServerHttpRequest request)
    {
        log.info("---------------------------    trace2   ----------------------------------");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name","wang");
        jsonObject.put("age","15");

//        log.info(" \n  TraceId={} \n  SpanId={} \n  ParentSpanId={} \n  Sampled={} \n  Name={}"
//                , request.getHeaders("X-B3-TraceId")
//                , request.getHeader("X-B3-SpanId")
//                , request.getHeader("X-B3-ParentSpanId")
//                , request.getHeader("X-B3-Sampled")
//                , request.getHeader("X-Span-Name"));


        JsonDto jsonDto = JsonDto.builder().age(11).name("wang").build();
        //log.error(JSON.toJSONString(request.getHeaders()));
        return new ResponseEntity<String>(jsonObject.toJSONString(), HttpStatus.OK);
    }
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    private static class JsonDto{
        private Integer age;
        private String name;
    }
}
